#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "scene.h"
#include "ctrlboard.h"
#include "mg_Lcd_Driver.h"
#include "mg_Device.h"
#include "mg_Rs485Protocol.h"
#include "mg_Rotate.h"
//设置模式显示
void Air_Mode_SetDisplay();
//设置风速显示
void Air_Fan_SetDisplay();
//设置风向显示
void Air_FanXiang_SetDisplay();
//获取空调的开关状态
static uint8_t Get_Air_Switch_State(void);
//设置空调的开关状态
static uint8_t Set_Air_Switch_State(uint8_t Switch);
//获取空调的设置温度
static uint8_t Get_Air_SetTemp_State(void);
//设置空调的设置温度
static uint8_t Set_Air_SetTemp_State(uint8_t SetTemp);
/* widgets:
Layer_KongTiao
Background_KongTiao
Container_KTOff_Button
PopupButton_KT_On
Container_KTOn_Button
Container_KT_VerticalFanXiangButton
PopupButton_KT_FanVerticalRight
PopupButton_KT_FanVerticalMiddle
PopupButton_KT_FanVerticalLeft
PopupButton_KT_FanVerticalAuto
Container_KT_LevelFanXiangButton
PopupButton_KT_FanLevelDown
PopupButton_KT_FanLevelMiddle
PopupButton_KT_FanLevelUp
PopupButton_KT_FanLevelAuto
Container_KT_FanButton
PopupButton_KT_FanAuto
PopupButton_KT_FanHigh
PopupButton_KT_FanMiddle
PopupButton_KT_FanLow
PopupButton_KT_OFF
Container_KT_Flash
Container_KT_FlashOn
PopupButton_KT_ModeFlash
Meter_KT_Flash_Xuanzhuan
Icon_KT_Flash_Pointer
CircleProgressBar_KT_Flash_Light
Text_KT_Flash_PercentNum
Icon_KT_Flash_Jingdu
Container_KT_FlashOff
Text_KT_FlashOFF
Icon_KT_FlashJindutiaoOff
Container_KT_Hum
Container_KT_HumOn
PopupButton_KT_ModeHum
Meter_KT_Hum_Xuanzhuan
Icon_KT_Hum_Pointer
CircleProgressBar_KT_Hum_Light
Text_KT_Hum_PercentNum
Icon_KT_Hum_Jingdu
Container_KT_HumOff
Text_KT_HumOFF
Icon_KT_HumJindutiaoOff
Container_KT_Hot
Container_KT_HotOn
PopupButton_KT_ModeHot
Meter_KT_Hot_Xuanzhuan
Icon_KT_Hot_Pointer
CircleProgressBar_KT_Hot_Light
Text_KT_Hot_PercentNum
Icon_KT_Hot_Jingdu
Container_KT_HotOff
Text_KT_HotOFF
Icon_KT_HotJindutiaoOff
Container_KT_Cold
Container_KT_ColdOn
PopupButton_KT_ModeCold
Meter_KT_Cold_Xuanzhuan
Icon_KT_Cold_Pointer
CircleProgressBar_KT_Cold_Light
Text_KT_Cold_PercentNum
Icon_KT_Cold_Jingdu
Container_KT_ColdOff
Text_KT_ColdOFF
Icon_KT_ColdJindutiaoOff
Button_Back_MainMenu
*/
static ITUBackground* Background_KongTiao;
static ITUContainer* Container_KT_On;
static ITUContainer* Container_KT_Off;
static ITUContainer* Container_KT_ColdOff;
static ITUContainer* Container_KT_ColdOn;
static ITUContainer* Container_KT_HotOff;
static ITUContainer* Container_KT_HotOn;
static ITUContainer* Container_KT_HumOff;
static ITUContainer* Container_KT_HumOn;
static ITUContainer* Container_KT_FlashOff;
static ITUContainer* Container_KT_FlashOn;
static ITUPopupButton* PopupButton_KT_FanLow;
static ITUPopupButton* PopupButton_KT_FanMiddle;
static ITUPopupButton* PopupButton_KT_FanHigh;
static ITUPopupButton* PopupButton_KT_FanAuto;
static ITUPopupButton* PopupButton_KT_FanLevelAuto;
static ITUPopupButton* PopupButton_KT_FanLevelUp;
static ITUPopupButton* PopupButton_KT_FanLevelMiddle;
static ITUPopupButton* PopupButton_KT_FanLevelDown;
static ITUPopupButton* PopupButton_KT_FanVerticalAuto;
static ITUPopupButton* PopupButton_KT_FanVerticalLeft;
static ITUPopupButton* PopupButton_KT_FanVerticalMiddle;
static ITUPopupButton* PopupButton_KT_FanVerticalRight;
static ITUCircleProgressBar	*CircleProgressBar_KT_Cold;
static ITUCircleProgressBar	*CircleProgressBar_KT_Hot;
static ITUCircleProgressBar	*CircleProgressBar_KT_Hum;
static ITUCircleProgressBar	*CircleProgressBar_KT_Flash;
static ITUMeter* Meter_KT_Xuanzhuan;
static ITUText	*Text_KT_TempNum;
static ITUText	*Text_KT_Cold, *Text_KT_Flash, *Text_KT_Hot, *Text_KT_Hum;
static int MeterValue = 0, MeterValue_L = 0;
bool KongTiaoOnEnter(ITUWidget* widget, char* param)
{
	if (!Background_KongTiao)//首次加载
	{
		Background_KongTiao = ituSceneFindWidget(&theScene, "Background_KongTiao");
		assert(Background_KongTiao);
		Container_KT_On = ituSceneFindWidget(&theScene, "Container_KT_On");
		assert(Container_KT_On);
		Container_KT_Off = ituSceneFindWidget(&theScene, "Container_KT_Off");
		assert(Container_KT_Off);
		Container_KT_ColdOff = ituSceneFindWidget(&theScene, "Container_KT_ColdOff");
		assert(Container_KT_ColdOff);
		Container_KT_ColdOn = ituSceneFindWidget(&theScene, "Container_KT_ColdOn");
		assert(Container_KT_ColdOn);
		Container_KT_HotOff = ituSceneFindWidget(&theScene, "Container_KT_HotOff");
		assert(Container_KT_HotOff);
		Container_KT_HotOn = ituSceneFindWidget(&theScene, "Container_KT_HotOn");
		assert(Container_KT_HotOn);
		Container_KT_HumOff = ituSceneFindWidget(&theScene, "Container_KT_HumOff");
		assert(Container_KT_HumOff);
		Container_KT_HumOn = ituSceneFindWidget(&theScene, "Container_KT_HumOn");
		assert(Container_KT_HumOn);
		Container_KT_FlashOff = ituSceneFindWidget(&theScene, "Container_KT_FlashOff");
		assert(Container_KT_FlashOff);
		Container_KT_FlashOn = ituSceneFindWidget(&theScene, "Container_KT_FlashOn");
		assert(Container_KT_FlashOn);
		PopupButton_KT_FanLevelAuto = ituSceneFindWidget(&theScene, "PopupButton_KT_FanLevelAuto");
		assert(PopupButton_KT_FanLevelAuto);
		PopupButton_KT_FanLevelUp = ituSceneFindWidget(&theScene, "PopupButton_KT_FanLevelUp");
		assert(PopupButton_KT_FanLevelUp);
		PopupButton_KT_FanLevelMiddle = ituSceneFindWidget(&theScene, "PopupButton_KT_FanLevelMiddle");
		assert(PopupButton_KT_FanLevelMiddle);
		PopupButton_KT_FanLevelDown = ituSceneFindWidget(&theScene, "PopupButton_KT_FanLevelDown");
		assert(PopupButton_KT_FanLevelDown);
		PopupButton_KT_FanVerticalAuto = ituSceneFindWidget(&theScene, "PopupButton_KT_FanVerticalAuto");
		assert(PopupButton_KT_FanVerticalAuto);
		PopupButton_KT_FanVerticalLeft = ituSceneFindWidget(&theScene, "PopupButton_KT_FanVerticalLeft");
		assert(PopupButton_KT_FanVerticalLeft);
		PopupButton_KT_FanVerticalMiddle = ituSceneFindWidget(&theScene, "PopupButton_KT_FanVerticalMiddle");
		assert(PopupButton_KT_FanVerticalMiddle);
		PopupButton_KT_FanVerticalRight = ituSceneFindWidget(&theScene, "PopupButton_KT_FanVerticalRight");
		assert(PopupButton_KT_FanVerticalRight);
		CircleProgressBar_KT_Cold = ituSceneFindWidget(&theScene, "CircleProgressBar_KT_Cold");
		assert(CircleProgressBar_KT_Cold);
		CircleProgressBar_KT_Hot = ituSceneFindWidget(&theScene, "CircleProgressBar_KT_Hot");
		assert(CircleProgressBar_KT_Hot);
		CircleProgressBar_KT_Hum = ituSceneFindWidget(&theScene, "CircleProgressBar_KT_Hum");
		assert(CircleProgressBar_KT_Hum);
		CircleProgressBar_KT_Flash = ituSceneFindWidget(&theScene, "CircleProgressBar_KT_Flash");
		assert(CircleProgressBar_KT_Flash);
		PopupButton_KT_FanLow = ituSceneFindWidget(&theScene, "PopupButton_KT_FanLow");
		assert(PopupButton_KT_FanLow);
		PopupButton_KT_FanMiddle = ituSceneFindWidget(&theScene, "PopupButton_KT_FanMiddle");
		assert(PopupButton_KT_FanMiddle);
		PopupButton_KT_FanHigh = ituSceneFindWidget(&theScene, "PopupButton_KT_FanHigh");
		assert(PopupButton_KT_FanHigh);
		PopupButton_KT_FanAuto = ituSceneFindWidget(&theScene, "PopupButton_KT_FanAuto");
		assert(PopupButton_KT_FanAuto);
		Meter_KT_Xuanzhuan = ituSceneFindWidget(&theScene, "Meter_KT_Xuanzhuan");
		assert(Meter_KT_Xuanzhuan);
		Text_KT_TempNum = ituSceneFindWidget(&theScene, "Text_KT_TempNum");
		assert(Text_KT_TempNum);
		Text_KT_Cold = ituSceneFindWidget(&theScene, "Text_KT_Cold");
		assert(Text_KT_Cold);
		Text_KT_Flash = ituSceneFindWidget(&theScene, "Text_KT_Flash");
		assert(Text_KT_Flash);
		Text_KT_Hot = ituSceneFindWidget(&theScene, "Text_KT_Hot");
		assert(Text_KT_Hot);
		Text_KT_Hum = ituSceneFindWidget(&theScene, "Text_KT_Hum");
		assert(Text_KT_Hum);
	}
	//更具参数初始化界面
	if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status == 1)//打开
	{
		ituWidgetSetVisible(Container_KT_On, true);
		ituWidgetSetVisible(Container_KT_Off, false);
	}
	else//关闭
	{
		ituWidgetSetVisible(Container_KT_On, false);
		ituWidgetSetVisible(Container_KT_Off, true);
	}
	//设置旋转进度
	ituMeterSetValue(Meter_KT_Xuanzhuan, TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Set_Temp / 2 - KT_Temp_Min);
	MeterValue = Meter_KT_Xuanzhuan->value;
	MeterValue_L = MeterValue;
	//判断显示模式
	Air_Mode_SetDisplay();
	//判断显示风速
	Air_Fan_SetDisplay();
	//判断显示风向
	Air_FanXiang_SetDisplay();
	//对标题进行语言转换
	if (Sys.Language == MG_LANGUAGE_CHS || Sys.Language == MG_LANGUAGE_ENG)
	{
		Text_KT_Cold->fontIndex = 0;
		Text_KT_Cold->boldSize = 1;
		ituTextSetFontSize(Text_KT_Cold, 18);
		Text_KT_Hot->fontIndex = 0;
		Text_KT_Hot->boldSize = 1;
		ituTextSetFontSize(Text_KT_Hot, 18);
		Text_KT_Flash->fontIndex = 0;
		Text_KT_Flash->boldSize = 1;
		ituTextSetFontSize(Text_KT_Flash, 18);
		Text_KT_Hum->fontIndex = 0;
		Text_KT_Hum->boldSize = 1;
		ituTextSetFontSize(Text_KT_Hum, 18);
	}
	else if (Sys.Language == MG_LANGUAGE_ZHTW)
	{
		Text_KT_Cold->fontIndex = 8;
		Text_KT_Cold->boldSize = 0;
		ituTextSetFontSize(Text_KT_Cold, 16);
		Text_KT_Hot->fontIndex = 8;
		Text_KT_Hot->boldSize = 0;
		ituTextSetFontSize(Text_KT_Hot, 16);
		Text_KT_Flash->fontIndex = 8;
		Text_KT_Flash->boldSize = 0;
		ituTextSetFontSize(Text_KT_Flash, 16);
		Text_KT_Hum->fontIndex = 8;
		Text_KT_Hum->boldSize = 0;
		ituTextSetFontSize(Text_KT_Hum, 16);
	}
	//Text操作
	char TextString[20]; 
	itoa(Get_Air_SetTemp_State(), TextString, 10);//转换成字符串
	ituTextSetString(Text_KT_TempNum, TextString);//显示字符
	Set_Rotate_Block(60);//旋转步进
    return true;
}

bool KongTiaoOnLeave(ITUWidget* widget, char* param)
{
	return true;
}

bool KongTiaoOnTimer(ITUWidget* widget, char* param)
{
	static uint32_t SendTime = Rotate_SendCmd_Time;

	//用户手势操作
	if (Action_Cmd.User_Action == Left_Slide || Action_Cmd.User_Action == Right_Slide)
	{
		GotoMainMenu();//返回主菜单
		Clear_User_Action();
	}

	//设备操作
	MeterValue = Meter_KT_Xuanzhuan->value;
	if (Get_Air_Switch_State() == 1)//设备开
	{
		if (Action_Cmd.User_Action == Clockwise_Rotation)//有用户操作
		{
			MeterValue += Action_Cmd.Action_Times;
			if (MeterValue > 15)MeterValue = 15;
			ituMeterSetValue(Meter_KT_Xuanzhuan, MeterValue);//设置Meter百分比值
			MessageFlag[MSG_GET_DEVICE_STATE_EN] = OFF;//关闭10s自动获取状态
			Clear_User_Action();
		}
		else if (Action_Cmd.User_Action == Anticlockwise_Rotation)
		{
			MeterValue -= Action_Cmd.Action_Times;
			if (MeterValue < 0)MeterValue = 0;
			ituMeterSetValue(Meter_KT_Xuanzhuan, MeterValue);//设置Meter百分比值
			MessageFlag[MSG_GET_DEVICE_STATE_EN] = OFF;//关闭10s自动获取状态
			Clear_User_Action();
		}
	}
	//设备状态执行
	if (MeterValue == MeterValue_L)
	{
		if (SendTime <= Rotate_SendCmd_Time)
			SendTime++;
		//停止操作0.6s后发送执行报文
		if (SendTime == Rotate_SendCmd_Time)
		{
			RS485_Set_TFTDeviceState(DisplayValue.TFT_Display_Device);
			MessageFlag[MSG_GET_DEVICE_STATE_EN] = ON;//允许10s自动获取状态
		}
	}
	else
	{
		SendTime = 0;
		MessageFlag[MSG_GET_DEVICE_STATE_EN] = OFF;//关闭10s自动获取状态
		Set_Air_SetTemp_State(MeterValue + KT_Temp_Min);
	}
	MeterValue_L = MeterValue;
	//设备状态更新
	if (MessageFlag[MSG_GUI_STATE_UPDATE] == ON)
	{
		if (Get_Air_Switch_State() == 1)//打开
		{
			ituWidgetSetVisible(Container_KT_On, true);
			ituWidgetSetVisible(Container_KT_Off, false);
			ituMeterSetValue(Meter_KT_Xuanzhuan, Get_Air_SetTemp_State() - KT_Temp_Min);
			MeterValue = Meter_KT_Xuanzhuan->value;
		}
		else//关闭
		{
			ituWidgetSetVisible(Container_KT_On, false);
			ituWidgetSetVisible(Container_KT_Off, true);
			ituMeterSetValue(Meter_KT_Xuanzhuan, Get_Air_SetTemp_State() - KT_Temp_Min);
			MeterValue = Meter_KT_Xuanzhuan->value;
		}
		//判断显示模式
		Air_Mode_SetDisplay();
		//判断显示风速
		Air_Fan_SetDisplay();
		//判断显示风向
		Air_FanXiang_SetDisplay();
		MessageFlag[MSG_GUI_STATE_UPDATE] = OFF;
		MeterValue_L = MeterValue;
	}
	//Text操作
	char TextString[20];
	itoa(Get_Air_SetTemp_State(), TextString, 10);//转换成字符串
	ituTextSetString(Text_KT_TempNum, TextString);//显示字符
    return true;
}

bool PopupButton_KT_ON_Press(ITUWidget* widget, char* param)
{
	Set_Air_Switch_State(ON);
	printf("Moorgen INFO : Touch to turn on the air conditioner\n");
	RS485_Set_TFTDeviceState(DisplayValue.TFT_Display_Device);
    return true;
}

bool PopupButton_KT_OFF_Press(ITUWidget* widget, char* param)
{
	Set_Air_Switch_State(OFF);
	printf("Moorgen INFO : Touch to turn off the air conditioner\n");
	RS485_Set_TFTDeviceState(DisplayValue.TFT_Display_Device);
    return true;
}
bool PopupButton_KT_FanXiangSet_Press(ITUWidget* widget, char* param)
{
	return true;
}
bool Meter_KT_Xuanzhuan_Changed(ITUWidget* widget, char* param)
{
	ituCircleProgressBarSetValue(CircleProgressBar_KT_Cold, Meter_KT_Xuanzhuan->value * 10);
	ituCircleProgressBarSetValue(CircleProgressBar_KT_Hot, Meter_KT_Xuanzhuan->value * 10);
	ituCircleProgressBarSetValue(CircleProgressBar_KT_Hum, Meter_KT_Xuanzhuan->value * 10);
	ituCircleProgressBarSetValue(CircleProgressBar_KT_Flash, Meter_KT_Xuanzhuan->value * 10);
	return true;
}
//设置模式显示
void Air_Mode_SetDisplay(void)
{
	uint8_t TempMode;
	if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		TempMode = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.Set_Mode;
	else
	{
		if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Extend_Mode)
			TempMode = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Extend_Mode;
		else
			TempMode = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Air_Status_Value.Byte.Mode;
	}

	//判断显示模式
	ituWidgetSetVisible(Container_KT_ColdOn, false);
	ituWidgetSetVisible(Container_KT_HotOn, false);
	ituWidgetSetVisible(Container_KT_HumOn, false);
	ituWidgetSetVisible(Container_KT_FlashOn, false);
	ituWidgetSetVisible(Container_KT_ColdOff, false);
	ituWidgetSetVisible(Container_KT_HotOff, false);
	ituWidgetSetVisible(Container_KT_HumOff, false);
	ituWidgetSetVisible(Container_KT_FlashOff, false);
	if (TempMode == 1)
	{
		//制冷
		ituWidgetSetVisible(Container_KT_ColdOn, true);
		ituWidgetSetVisible(Container_KT_ColdOff, true);
	}
	else if (TempMode == 2)
	{
		//除湿
		ituWidgetSetVisible(Container_KT_HumOn, true);
		ituWidgetSetVisible(Container_KT_HumOff, true);
	}
	else if (TempMode == 3)
	{
		//通风
		ituWidgetSetVisible(Container_KT_FlashOn, true);
		ituWidgetSetVisible(Container_KT_FlashOff, true);
	}
	else if (TempMode == 4)
	{
		//制热
		ituWidgetSetVisible(Container_KT_HotOn, true);
		ituWidgetSetVisible(Container_KT_HotOff, true);
	}
	else
	{
		//制冷
		ituWidgetSetVisible(Container_KT_ColdOn, true);
		ituWidgetSetVisible(Container_KT_ColdOff, true);
	}
}
//设置风速显示
void Air_Fan_SetDisplay(void)
{
	uint8_t TempSpeed = 0;
	if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		TempSpeed = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.Set_Speed;
	else
	{
		if (TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Extend_Mode)
			TempSpeed = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Extend_Speed;
		else
			TempSpeed = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Air_Status_Value.Byte.Speed;
	}

	//判断显示风速
	ituWidgetSetVisible(PopupButton_KT_FanLow, false);
	ituWidgetSetVisible(PopupButton_KT_FanMiddle, false);
	ituWidgetSetVisible(PopupButton_KT_FanHigh, false);
	ituWidgetSetVisible(PopupButton_KT_FanAuto, false);
	if (TempSpeed == 0)
	{
		//自动
		ituWidgetSetVisible(PopupButton_KT_FanAuto, true);
	}
	else if (TempSpeed == 1)
	{
		//低风
		ituWidgetSetVisible(PopupButton_KT_FanLow, true);
	}
	else if (TempSpeed == 2)
	{
		//中风
		ituWidgetSetVisible(PopupButton_KT_FanMiddle, true);
	}
	else if (TempSpeed == 3)
	{
		//高风
		ituWidgetSetVisible(PopupButton_KT_FanHigh, true);
	}
}
//设置风向显示
void Air_FanXiang_SetDisplay(void)
{
	IT_AIR_FANXIANG TempFanXiang;
	//判断显示风向
	Clear_User_Action();
	ituWidgetSetVisible(PopupButton_KT_FanLevelAuto, false);
	ituWidgetSetVisible(PopupButton_KT_FanLevelUp, false);
	ituWidgetSetVisible(PopupButton_KT_FanLevelMiddle, false);
	ituWidgetSetVisible(PopupButton_KT_FanLevelDown, false);
	ituWidgetSetVisible(PopupButton_KT_FanVerticalAuto, false);
	ituWidgetSetVisible(PopupButton_KT_FanVerticalLeft, false);
	ituWidgetSetVisible(PopupButton_KT_FanVerticalMiddle, false);
	ituWidgetSetVisible(PopupButton_KT_FanVerticalRight, false);
	if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		return;
	else
		TempFanXiang = TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.FanXiang;
	
	if (TempFanXiang.vol != 0)
	{
		if (TempFanXiang.Byte.FanLevel == 1)
		{
			//水平自动
			ituWidgetSetVisible(PopupButton_KT_FanLevelAuto, true);
		}
		else if (TempFanXiang.Byte.FanLevel == 2)
		{
			//水平向下
			ituWidgetSetVisible(PopupButton_KT_FanLevelUp, true);//和APP的UI反了，做更正
		}
		else if (TempFanXiang.Byte.FanLevel == 3)
		{
			//水平向上
			ituWidgetSetVisible(PopupButton_KT_FanLevelDown, true);//和APP的UI反了，做更正
		}
		
		if (TempFanXiang.Byte.FanVertical == 1)
		{
			//垂直自动
		}
		else if (TempFanXiang.Byte.FanVertical == 2)
		{
			//垂直向左
		}
		else if (TempFanXiang.Byte.FanVertical == 3)
		{
			//垂直向右
		}
	}
}
//获取空调的开关状态
static uint8_t Get_Air_Switch_State(void)
{
	if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		return TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.status;
	else
		return TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status;
}
//设置空调的开关状态
static uint8_t Set_Air_Switch_State(uint8_t Switch)
{
	if (Switch == ON)
	{
		if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.status = 1;//状态开
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.status = 0x52;//命令开
		}
		else
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status = 1;//状态开
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status = 0x52;//命令开
		}
	}
	else if (Switch == OFF)
	{
		if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.status = 0;//状态开
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.status = 0x53;//命令开
		}
		else
		{
			TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status = 0;//状态开
			TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status = 0x53;//命令开
		}
	}
}
//获取空调的设置温度
static uint8_t Get_Air_SetTemp_State(void)
{
	if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
		return TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.Set_Temp;
	else
		return TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Set_Temp / 2;
}
//设置空调的设置温度
static uint8_t Set_Air_SetTemp_State(uint8_t SetTemp)
{
	if (TFT_Device[DisplayValue.TFT_Display_Device].TFTSCEQ.TFT_Device.DeviceType == DEVIC_TYPE_MATCH_CODE_AIRCONDITION)
	{
		TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.Set_Temp = SetTemp;
		TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.status = 0x54;//设置温度
		TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Matching_Air_Status.Set_Temp = SetTemp;
	}
	else
	{
		TFT_Device_State[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Set_Temp = SetTemp * 2;
		TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.status = 0x54;//设置温度
		TFT_Device_Cmd[DisplayValue.TFT_Display_Device].IT_Dev_STatus_Value.IT_Air_Status.Set_Temp = SetTemp * 2;
	}
}